<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../res/layui/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <script src="../../../res/layui/layui.js" charset="utf-8"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <script src="../../../res/js/jquery-3.4.1.js" charset="utf-8"></script>
    <script src="../../../res/js/util.js" charset="utf-8"></script>
</head>
<body style="padding: 10px">

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>增加会员</legend>
</fieldset>

<form class="layui-form" action="" lay-filter='myform' id="myform">
    <input type="hidden" name="memberId" id="memberId">

    <div class="layui-form-item" >
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block"  >
            <input type="radio" name="sex" value="男" title="男" checked="" >
            <input type="radio" name="sex" value="女" title="女" >
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">会员折扣</label>
        <div class="layui-input-block">
            <input type="text" name="discount" id="discount"
                   placeholder="请输入会员折扣"  maxlength="4" lay-verify="required|xiaoshu"  class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">会员账号</label>
        <div class="layui-input-block">
            <input type="text" name="memberAccout" id="memberAccout"
                   placeholder="请输入会员账号"  lay-verify="required"      class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">会员密码</label>
        <div class="layui-input-block">
            <input type="text" name="memberPassword" id="memberPassword"
                   lay-verify="required" autocomplete="off"
                  placeholder="请输入会员密码"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">电话号码</label>
        <div class="layui-input-block">
            <input type="text" name="memberPhone" id="memberPhone"
                   lay-verify="required | phone" autocomplete="off"
                   placeholder="请输入电话号码"
                   class="layui-input">
        </div>
    </div>



    <div class="layui-form-item">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <input type="text" name="remark2" id="remark2"
                   lay-verify="required" autocomplete="off"
                   placeholder=""
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" class="layui-btn layui-btn-normal"
                    id="LAY-quxiao">取消</button>
            <button type="submit" class="layui-btn" lay-submit=""
                    lay-filter="add">立即提交</button>
        </div>
    </div>
    <input type="hidden" id="fid">
</form>

<script>

   /* //全局同步
    $.ajaxSetup({
        async: false
    });
*/
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,$ = layui.$;

        form.verify({
            xiaoshu: [
                /^(([^0][0-9]+|0)\.([0-9]{1,2}))$/
                ,'折扣填写俩位或一位小数小数'
            ]

            ,content: function(value){
                layedit.sync(editIndex);
            }
        });

        //监听提交
        form.on('submit(add)', function(data){

            var url ="../../../immMember/addOrUpdate";
            var formData = data.field;
            console.info(formData);
            $.ajax({
                url:url,
                data:formData,
                dataType:'json',
                type:'POST',
                success:function (obj) {
                    if(obj.status == 1){
                        parent.layui.table.reload("testReload");
                        // var index = parent.layer.getFrameIndex(window.name);
                        // parent.layer.close(index);

                        table.reload('myform'); //刷新表格
                    }else if(obj.status ==50){
                        layer.msg(obj.message);
                    }
                },
                error:function () {

                }
            })
            return false;
        });




        //表单赋值
        var memberId = getQueryString("memberId");
        if(memberId){
            console.info(memberId);
            var url = "../../../immMember/selectOne";
            var data = {id:memberId};
            $.post(url,data,function(obj){
                console.info(obj);
                form.val('myform',obj);
            },"json");
        };


        //表单取值
        layui.$('#LAY-component-form-getval').on('click', function(){
            var data = form.val('example');
            alert(JSON.stringify(data));
        });



    });



</script>

</body>
</html>